package tst

class A3
{
	def static apply(self, Closure closure)
	{
		println "self:${self.toString()},superclass:${self.getClass().superclass.name}"
		def context =  self instanceof Closure ? self.delegate: self;
		println "context:${context.toString()},superclass:${context.getClass().superclass.name}"
		return context.with(closure)
	}
}

class B3
{
	static Closure rule= {
		println 'B'
		apply(C3.rule)
	}
}

class C3
{
	static Closure rule= {
		println 'C'
		apply(D3.rule)
	}
}

class D3
{
	static Closure rule= {
		println "D,variables:${var}"
		ret = 'success'
	}
}

var = 'helloworld'

use(A3)
{
	apply(B3.rule);
	println ret;
	println this.binding.variables;
}

